package com.yootk.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

//@WebServlet("/hello.action") // 直接使用默认的value属性进行匹配
/*@WebServlet(description = "使用注解实现的Servlet的配置，适用于Servlet 3.0标准之后",
            urlPatterns = {"/hello.action", "/muyan.yootk", "/muyan/yootk/*"})*/
public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 在doGet()方法中已经明确的给出了HttpServletRequest、HttpServletResponse接口实例
        // 这个接口实例是在每一次进行请求处理的时候，由容器负责提供的
        // 在Java中提供了两个打印流：PrintStream、PrintWriter，HTML实际上是文本，所以字符流合适
        PrintWriter out = resp.getWriter(); // 获得了客户端浏览器的输出流
        out.println("<html>");
        out.println("<head>");
        out.println("   <title>Yootk - JavaWEB</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("   <h1>www.yootk.com</h1>");
        out.println("</body>");
        out.println("</html>");
        out.close(); // 关闭输出流
    }
}
